/**
 * @file RegMapper.h
 *
 *  @date 27 jan 2012
 *  @author Calle Olsen
 */

#ifndef REGMAPPER_H_
#define REGMAPPER_H_
#include <string>
#include <map>
#include <vector>

using namespace std;

/**
 * \class RegMapper RegMapper.h <Helpers/RegMapper.h>
 *
 * \brief connects key str to a multiset of certain classes (U)
 *
 * This is basically an re-implementation of multimap.
 * This is used by the @see RegProvider
 *
 *
 */
template< class U >
class RegMapper {
public:
	typedef U ValueClass; /// Value class definition
	typedef multimap< string, U> MapDef; /// Multimap definition
	typedef vector< U > VectorDef; /// Vector definition...


	RegMapper(){};
	virtual ~RegMapper(){};

	/**
	 * \brief adds a new value to regmapper.
	 *
	 * Adds a new Class to the regmapper registry.
	 * It is allowed to have several of the same key.
	 *
	 * \param[in]
	 */
	void add(const string& keyStr, U value );

	/**
	 * \brief finds all with the argument name
	 *
	 * Returns a vector with all the found items
	 *
	 * \param[in] keyStr key to be found.
	 */
	VectorDef find(const string& keyStr) const;
private:
	MapDef m_Mapper; ///Map instance
};


template< class U>
void RegMapper<U>::add(const string& keyStr,  U value )
{
	m_Mapper.insert(pair<string,U>(keyStr,value));

}

template< class U>
typename RegMapper<U>::VectorDef RegMapper<U>::find(const string& keyStr) const
{
	typename MapDef::const_iterator iter = m_Mapper.find(keyStr);
	VectorDef arr(iter,m_Mapper.end());
	return arr;

}
#endif /* REGMAPPER_H_ */
